package Year22_Month04.day21;

public class 两两交换链表中的元素 {
    public static ListNode swapPairs(ListNode head) {
        ListNode slow = head;
        while(slow != null && slow.next != null){
            ListNode fast = slow.next;
            int tmp = slow.val;
            slow.val = fast.val;
            fast.val = tmp;
            if(slow.next.next != null){
                slow = slow.next.next;
            }else{
                break;
            }
        }
        return head;
    }

    public static void main(String[] args) {
        ListNode listNode1  = new ListNode(1);
        ListNode listNode2 = new ListNode(2);
        ListNode listNode3  = new ListNode(3);
        ListNode listNode4  = new ListNode(4);
        listNode1.next = listNode2;
        listNode2.next = listNode3;
        listNode3.next = listNode4;
        System.out.println(swapPairs(listNode1));
    }
}
